package com.example.fuluchou.dao.mapper;

import com.example.fuluchou.dao.dataobject.PrizeDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PrizeMapper {

    @Insert("insert into prize(description,image_url,name,price)" +
            " values (#{description},#{imageurl},#{name},#{price})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void insert(PrizeDO prizeDO);

    @Select("select count(1) from prize")
    Long count();

    /**
     * 翻页查询
     * @param offset
     * @param pageSize
     * @return
     */
    @Select("select * from prize order by id desc limit #{offset},#{pageSize}")
    List<PrizeDO> queryPrizesByPage(@Param("offset") Integer offset,@Param("pageSize") Integer pageSize);

    @Select("<script>" +
            " select id from prize" +
            " where id in" +
            " <foreach item='item' collection='list' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<Long> selectExistByids(@Param("list") List<Long> prizeIds);

    @Select("<script>" +
            " select * from prize" +
            " where id in" +
            " <foreach item='item' collection='list' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<PrizeDO> batchSelectByIds(@Param("list") List<Long> needPrizeIds);

    @Select("select * from prize where id = #{id}")
    PrizeDO selectById(@Param("id")Long id);
}
